<template>
	<view>
		<view class="search">
			<view class="search-box">
				<view class="icon">
					<image src="/static/search.png"></image>
				</view>
				<input v-model="searchText" @confirm="handleSearch" type="text" class="search-input" confirm-type="search"
				 :placeholder="placeholder">
			</view>
			<text v-if="isShowAdd" class="add" @click="goAdd">
				+
			</text>
			<text v-if="isShowAdd" @click="goAdd" style="color: #5094FF;">{{addText}}</text>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			placeholder: {
				type: String,
				default: '请输入设施具体位置'
			},
			addText: {
				type: String,
				default: '新增设施'
			},
			isShowAdd: {
				type: Boolean,
				default: true
			}
		},
		data() {
			return {
				searchText: ''
			};
		},
		watch: {
			searchText() {
				if(this.searchText == '') {
					this.$emit('reset')
				}
			}
		},
		methods: {
			goAdd() {
				this.$emit('add')
			},
			handleSearch() {
				this.$emit('search', this.searchText)
			}
		}
	}
</script>

<style lang="scss">
	.search {
		// margin-left: 100rpx;
		width: 750rpx;
		height: 96rpx;
		background-color: #fff;
		display: flex;
		align-items: center;
		padding-left: 50rpx;
		margin-bottom: 20rpx;
		.search-box {
			width: 500rpx;
			height: 56rpx;
			padding-left: 17rpx;
			padding-right: 20rpx;
			margin-right: 20rpx;
			// background-color: pink;
			border: 2rpx solid #595959;
			border-radius: 28rpx;
			display: flex;
			.icon {
				width: 50rpx;
				height: 46rpx;
				margin-top: 3rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}
			.search-input {
				flex: 1;
				height: 100%;
				color: #999;
			}
			.pop {
				position: absolute;
				right: 60rpx;
			}
		}
		.add {
			font-size: 32rpx;
			font-weight: bold;
			color: #5094FF;
			margin-right: 4rpx;
		}
	}
</style>
